<!--
**********************************************************
* @Author: 张小平
* @Date:   2024-05-01
* @Email:  qqshuqian@163.com
* @Last modified: 最后修改日期
* @Description: 文件描述
**********************************************************
-->
<template>

  <el-container>

    <el-header>

      <el-row>

        <el-col :span="16">
          <el-input
                  type="textarea"
                  :rows="2"
                  placeholder="请输入内容"
                  v-model="qureyValue">
          </el-input>

        </el-col>
        <el-col :span="8">
          <el-button type="primary" @click="qureyData">查询</el-button>
        </el-col>

      </el-row>


    </el-header>

    <el-main>

      <avue-crud
              :option="option"
              :data="tableData"
      >
      </avue-crud>

    </el-main>
  </el-container>

</template>
<script>
  import {getAiData} from '@/framework-core/api/ai'

  export default {
    name: "ai-data",
    data() {
      return {
        qureyValue:"",
        option: {border:false,header:true,menu:false,disabled:true,readonly:true,menuBtn:false,addBtn:false},
        tableData:[],
      };
    },

    methods: {
      qureyData() {
        var data = {};
        data.msg = this.qureyValue;
        data.ds = "test";
        getAiData(data).then(response => {
          let tableDataTemps  = [];
          let columns = [];
          if(response.data.data.data) {
            let rowTableData = {};
            for (let dataRowIndex = 0; dataRowIndex < response.data.data.data.length; dataRowIndex++) {
              debugger
              let drowMap = response.data.data.data[dataRowIndex];
              Object.entries(drowMap).map(([key, value]) => {
                if (dataRowIndex == 0) {
                  columns.push({"type": "input", "label": key, "prop": key})
                }
                rowTableData[key] = value;
                dataRowIndex++
              })
              tableDataTemps.push(rowTableData);
            }

            this.option.column = columns;
            this.tableData = tableDataTemps;

          }
          alert(JSON.stringify(response.data.data))
        }).catch(error => {
          this.$message.error(error.msg || error.message)
        })
      }
    }
  };
</script>
<style lang="scss">

</style>
